<?php 
namespace Admin\Controller;
use Think\Controller;
class GoodsController extends Controller{
	public function goodsadd(){
		if(!IS_POST){
			$this->display();
		}else{
			$goodsModel = D('Goods');
			$upload = new \Think\Upload();
			$upload->exts = array('jpeg','gif','png','jpg');
			$upload->rootpath = './Public/Uploads/';
			$info = $upload->Upload();
			if(!$info){
				var_dump($upload->getError());
				exit();
			}else{
				$_POST['goods_img'] = '/Public/Uploads/'.$info['goods_img']['savepath'].$info['goods_img']['savename'];
				$path = './Public/Uploads/'.$info['goods_img']['savepath'].$info['good_img']['savename'];
				$img = new \Think\Image();
				$img->open($path);
				$thumb_path = '/Public/Uploads/thumb/'.$info['goods_img']['savename'];
				$img->thumb(230,230)->save($thumb_path);
				$_POST['thumb'] = $thumb_path;
			}

			if($goodsModel->create()){
				$goodsModel->add();
			}else{
				exit($goodsModel->getError());
			}
		}
	}

	public function goodslist(){
		$goodsModel = D('Goods');
		$count = $goodsModel->count();
		$page = new \Think\page($count,10);
		$show = $page->show();
		$goodsModel->field('goods_id,goods_name,goods_sn,shop_price,is_on_sale,is_new,is_hot,is_best,goods_number');
		$goods = $goodsModel->order('goods_id desc')->limit($page->firstRow.','.$page->listRows);
		$this->assign('page',$show);
		$this->assign('goods',$goods);
		$this->display();
	}

	public function goodsdel(){
		$goodsModel = D('Goods');
		if($goodsModel->delete(I('get.goods_id'))){
			$this->redirect('Admin/Goods/goodslist');
		}else{
			exit($goosModel->getError());
		}
	}
}